#include "foodtypecombobox.h"

FoodTypeComboBox::FoodTypeComboBox(QWidget *parent) :
    QComboBox(parent)
{
}

void FoodTypeComboBox::initialize(QSqlDatabase *db)
{
    addItem(tr("Minden élelmiszer"), -1);

    QSqlQuery *query = new QSqlQuery(*db);
    if (query->exec("SELECT rowid, name FROM foodtypes")) {
        while (query->next()) {
            addItem(query->value(1).toString(), query->value(0));
        }
    } else {
        qWarning() << tr("Adatbázishiba: ") << query->lastError().databaseText();
    }
}
